﻿module Sustainalytics.Research {

    // controller used for ResearchMenuIndex (located on index page)
    export class ResearchMenuIndexController {

        public companyNameQueryString: string;
        public gcPermissions: GCCS.Security.GCPermissions;
        public hasMultiCompanyPI: boolean;
        public multiCompanyReportLink: string;
        public hasPortfolioPermission: boolean;

        constructor(
            private $rootScope: ng.IScope,
            private $scope: ng.IScope,
            private $q: ng.IQService,
            private $routeParams: ng.route.IRouteParamsService,
            private $location: ng.ILocationService,
            private GCPermissionsService: Sustainalytics.GCCS.Security.GCPermissionsService,
            private PIPermissionsService: Sustainalytics.ProductInvolvement.Security.PIPermissionsService,
            private PortfolioService: Sustainalytics.Portfolio.PortfolioService
            )
        {

            var ctx = this;
            $scope['researchMenuIndex'] = ctx;

            // get company name from route params
            //var companyName: string = ctx.$routeParams['companyName'];
            //ctx.companyNameQueryString = companyName;

            ctx.$rootScope.$watch('authData', function () {
                // get GCCS permissions
                ctx.gcPermissions = ctx.GCPermissionsService.getPermissions();
                ctx.hasMultiCompanyPI = ctx.PIPermissionsService.hasMultiCompanyPI();    
                
                //not working properly now
                //ctx.multiCompanyReportLink = !ctx.hasMultiCompanyPI ? '' : '#/research/pi';
                //ctx.hasPortfolioPermission = ctx.PortfolioService.hasPermision();
            });

            ctx.multiCompanyReportLink = '#/research/pi';
            ctx.hasPortfolioPermission = true;
        }

        // get current location path
        public getCurrentPath(): string {
            var ctx = this;
            return ctx.$location.path();
        }

    }

    angular.module('Sustainalytics.Research').controller('ResearchMenuIndexController', ResearchMenuIndexController);
} 